import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/*
 * @author zzr
 * @date: 2025/10/11  17:44
 * @description:
 */
public class CardList {

    private static final String[] SUITS = {"♦", "♥", "♠", "♣"};

    /**
     * 获得 52 张牌
     * @return
     */
    public static List<Card> getCards() {
        List<Card> list = new ArrayList<>();

        for (int i = 0; i < SUITS.length; i++) {
            for (int j = 1; j < 14; j++) {
                String suit = SUITS[i];
                Card card = new Card(j,suit);
                list.add(card);
            }
        }
        return list;
    }

    private static void shuffle(List<Card> list) {
        Random random = new Random();
        for (int i = list.size() - 1; i > 0; i--) {
            int randomIndex = random.nextInt(i);
            swap(list,i,randomIndex);
        }
    }

    private static void swap(List<Card> list, int i, int randomIndex) {
        Card tmp = list.get(i);
        list.set(i,list.get(randomIndex));
        list.set(randomIndex,tmp);
    }

    public static void main(String[] args) {
        List<Card> list = getCards();
        System.out.println("牌堆的牌");
        System.out.println(list);

        System.out.println("洗牌后");
        shuffle(list);
        System.out.println(list);

        // 每个人存起来自己的牌 二维数组
        List<List<Card>> hand = new ArrayList<>();
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();

        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);

        // 发牌
        for (int i = 0; i < 5; i++) {
            //发五轮
            for (int j = 0; j < 3; j++) {
                // 三个人
                Card card = list.remove(0);
                hand.get(j).add(card);
            }
        }
        System.out.println("第一个人的牌：" + hand.get(0));
        System.out.println("第一个人的牌：" + hand.get(1));
        System.out.println("第一个人的牌：" + hand.get(2));
        System.out.println("剩下的牌：" + list);
    }
}
